<?php

/**
 * Object/XExecuter.php
 */

namespace RHX\Model\Object;

use Zend\Db\Adapter\Adapter;
use RHX\Model\Object\Action;
use RHX\Model\Object\Tache;

class XExecuter {

    protected $adapter;
    protected $action = null;
    protected $tache;

    /**
     * Constructeur
     *
     * @param \Zend\Db\Adapter\Adapter $adapter
     * @param \RHX\Model\Object\Action $action
     */
    public function __construct(Adapter $adapter, Tache $tache) {
	$this->adapter	 = $adapter;
	$this->tache	 = $tache;
    }

    /**
     *
     * @return Adapter
     */
    public function getAdapter() {
	return $this->adapter;
    }

    /**
     *
     * @return Tache
     */
    public function getTache() {
	return $this->tache;
    }

    /**
     *
     * @return Action
     */
    public function getAction() {
	if (is_null($this->action)) {
	    $this->action = $this->getTache()
		    ->getAction();
	}

	return $this->action;
    }

    /**
     * Exécuter la tache
     * 
     * @return boolean
     */
    public function execute() {
	$action		 = $this->getAction();
	$function	 = $action->function;
	if (is_callable($function)) {
	    $this->$function($this->getTache()->param);
	    return true;
	}
	return false;
    }

}

?>
